package com.labor_management_system.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.labor_management_system.Entity.WorkDetails;
import com.labor_management_system.Service.WorkDetailsService;
import com.labor_management_system.Mapper.WorkDetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author deathwing475
* @description 针对表【work_details】的数据库操作Service实现
* @createDate 2024-02-27 09:55:04
*/
@Service
public class WorkDetailsServiceImpl extends ServiceImpl<WorkDetailsMapper, WorkDetails>
    implements WorkDetailsService {
    //工程明细


    @Override
    public Boolean inserBatchList(List<WorkDetails> workDetailsList) {
        int row =0;

        for (int i=0;i<workDetailsList.size();i++){
            baseMapper.insert(workDetailsList.get(i));
            row++;
        }

        if(row==workDetailsList.size()){
            return true;
        }

        return false;
    }

    @Override
    public Boolean updateBatchList(List<WorkDetails> workDetailsList,String laborEngineeringId) {
        int update =0;

        for (int i=0;i<workDetailsList.size();i++){
            //判断是新增还是更新
            QueryWrapper<WorkDetails> queryWrapper = new QueryWrapper<>();

            queryWrapper.eq("work_details_id",workDetailsList.get(i).getWorkDetailsId());

            update = baseMapper.update(workDetailsList.get(i),queryWrapper);

            if(update ==0){
                //判断更新成功否，如果新增的没有id，换成新增
                workDetailsList.get(i).setLaborEngineeringId(laborEngineeringId);
                baseMapper.insert(workDetailsList.get(i));
            }

            update =0;
        }

        return true;
    }

    @Override
    public void deleteworkDetails(String workDetailsId) {
        baseMapper.deleteById(workDetailsId);
    }

    @Override
    public List<WorkDetails> selectListByEngineerId(String laborEngineeringId) {
        QueryWrapper<WorkDetails> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("labor_engineering_id",laborEngineeringId);

        return baseMapper.selectList(queryWrapper);
    }
}




